package slef.xchen;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author chenxing
 */
public class DataHub {
	private static final Map<String, Map<String, Slot<?>>> dataHub = new ConcurrentHashMap<>();

	public synchronized static void set(String tableName, String index, Slot<?> slot) {
		Map<String, Slot<?>> tableSlotMap = dataHub.computeIfAbsent(tableName, k -> new HashMap<>());
		tableSlotMap.put(index, slot);
	}

	public synchronized static Slot<?> get(String tableName, String index) {
		Map<String, Slot<?>> tableSlotMap = dataHub.get(tableName);
		if (null == tableSlotMap) {
			return null;
		}
		return tableSlotMap.get(index);
	}

	public synchronized static void delete(String tableName, String index) {
		Map<String, Slot<?>> tableSlotMap = dataHub.get(tableName);
		if (null == tableSlotMap) {
			return;
		}
		tableSlotMap.remove(index);
	}
}
